#ifndef UINTERFACE_H
#define UINTERFACE_H

#include <windows.h>
#include <string>
#include <QDebug>
#include <assert.h>
#include <cstdlib>
using namespace std;

class uInterface {
public:
    static void ReadXBytesFromPort(HANDLE port,BYTE* ioBuffer,int numberOfBytesToRead) {
#ifdef MY_DEBUG
        qDebug()<<"in function : ReadXBytesFromPort";
#endif
        DWORD get;
        DWORD num=0;
        while (num<numberOfBytesToRead) {
            assert(port!=HANDLE(-1));
            ReadFile(port,LPVOID(ioBuffer+num), numberOfBytesToRead-num, &get, NULL);
            num+=get;
#ifdef MY_DEBUG
            qDebug()<<"get:"<<get<<"num:"<<num;
#endif
        }
    }
    static wstring s2ws(const string& s) {
        int len, slength = int(s.length())+1;
        len = MultiByteToWideChar(CP_ACP,0,s.c_str(),slength,0,0);
        wchar_t * buf = new wchar_t[len];
        MultiByteToWideChar(CP_ACP,0,s.c_str(),slength,buf,len);
        wstring r(buf);
        delete [] buf;
        return r;
    }
};

#endif // UINTERFACE_H
